﻿using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infastruucture;
using BasicData.Read.API.application.Command.Permission;
using MediatR;

namespace BasicData.Read.API.application.CommandHandler.Permission
{
    public class GetPermissioListCommandHandler : IRequestHandler<GetPermissioListCommand, ApiResult<List<PermissionModel>>>
    {
        private readonly IBaseRepository<PermissionModel> permissionRepo;

        public GetPermissioListCommandHandler(IBaseRepository<PermissionModel> permissionRepo)
        {
            this.permissionRepo = permissionRepo;
        }
        public Task<ApiResult<List<PermissionModel>>> Handle(GetPermissioListCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<PermissionModel>> res = new ApiResult<List<PermissionModel>>();
            res.Code = BaseEnums.Success; ;
            res.Msg = "权限列表查询成功";
            var list = permissionRepo.GetAll();
            res.Data = list.ToList();
            return Task.FromResult(res);
        }
    }
}
